package com.i2works.smartluolong.manage.config;

import com.i2works.smartluolong.utils.config.BeetlConfigurationUtils;
import org.beetl.ext.spring.BeetlGroupUtilConfiguration;
import org.beetl.ext.spring.BeetlSpringViewResolver;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * beelt配置
 *
 * @author Liu Yutao <koal@vip.qq.com>
 * @date 2017/12/13 14:48
 */
@Configuration
public class BeetlConfiguration {

    /**
     * 模板路径（默认：templates）
     */
    @Value("${beelt.templates.path}")
    private String beeltTemplatesPath;
    /**
     * 配置文件（默认：config/beetl.properties）
     */
    @Value("${beelt.properties.path}")
    private String beeltPropertiesPath;
    /**
     * 模板后缀（默认：.html）
     */
    @Value("${beelt.suffix}")
    private String beeltSuffix;


    /**
     * beetl配置器
     */
    @Bean(initMethod = "init", name = "beetlConfig")
    public BeetlGroupUtilConfiguration getBeetlGroupUtilConfiguration() {
        return BeetlConfigurationUtils.getBeetlGroupUtilConfiguration(beeltTemplatesPath, beeltPropertiesPath);
    }

    /**
     * beetl视图解析器
     */
    @Bean(name = "beetlViewResolver")
    @Qualifier("beetlConfiguration")
    public BeetlSpringViewResolver getBeetlSpringViewResolver(BeetlGroupUtilConfiguration beetlGroupUtilConfiguration) {
        return BeetlConfigurationUtils.getBeetlSpringViewResolver(beetlGroupUtilConfiguration, beeltSuffix);
    }

}
